package com._520it.crm.service.impl;

import com._520it.crm.domain.Product;
import com._520it.crm.mapper.ProductMapper;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.QueryObject;
import com._520it.crm.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 呆 on 2017/10/3.
 */
@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return productMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Product product) {
        return productMapper.insert(product);
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Product product) {
        return productMapper.updateByPrimaryKey(product);
    }

    @Override
    public PageResult query(QueryObject qo) {
        Integer totalCount = productMapper.queryforCount(qo);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Product> data = productMapper.queryforList(qo);
        return new PageResult(totalCount,data);
    }

    @Override
    public List<Product> selectByOrgId(Long orgId) {
        return productMapper.selectByOrgId(orgId);
    }

    @Override
    public List<Product> selectByOrderId(Long orderBillId) {
        return productMapper.selectByOrderId(orderBillId);
    }


}
